/**   
 * @Title: ShiyixuanwuChooseOkPage.java 
 * @Package com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu 
 * @Description: 选好了界面
 * @Author: Miko baoz@500wan.com   
 * @Date: 2011-6-27 下午07:39:01  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu;

import java.util.ArrayList;
import java.util.Hashtable;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.model.UserInfo;
import com.esun.network.communicater.UserCommunicater;
import com.esun.rabbit2.communicaters.shiyixuanwu.BuyingCommunicater;
import com.esun.rabbit2.viewer.LoginAct;
import com.esun.rabbit2.viewer.WebViewActivity;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk.ShiyixuanwuBuyingInfo;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk.ShiyixuanwuContainer;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk.ShiyixuanwuPlayStyle;
import com.esun.rabbit2.viewer.mainact.mylotteryact.recharg.RechargeMenuPage;
import com.esun.ui.R;
import com.esun.util.LoginTimeControl;
import com.esun.util.ViewerUtil;
import com.esun.util.log.EDebug;
import com.esun.util.wheel.widget.NumericWheelAdapter;
import com.esun.util.wheel.widget.OnWheelChangedListener;
import com.esun.util.wheel.widget.OnWheelScrollListener;
import com.esun.util.wheel.widget.WheelView;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnDismissListener;

import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

/**
 * @ClassName: ShiyixuanwuChooseOkPage
 * @Description: 选好了界面
 * @Author: Miko baoz@500wan.com
 * @Date: 2011-6-27 下午07:39:01
 * 
 */
public class ShiyixuanwuChooseOkPage implements OnClickListener {

	/** 等待City整理 */
	private final static String LEFT_TAG = "[";
	private final static String RIGHT_TAG = "]";
	private final static String ZHU = "注 ";
	private final static String YUAN = "元";

	private View view; // 选好了界面的view

	private View btnGoBackChoose; // 继续选号按钮
	private View btnAddRandom; // 增加机选按钮
	private View btnClear; // 清空按钮
	private Button btnBuy; // 购买按钮

	private Context context; // 十一选五的Activity

	private ShiyixuanwuContainer container; // 选号界面对象

	private LinearLayout lineNumList; // 已选号码的列表

	private LayoutInflater inflater;

	private View.OnClickListener itemListener;

	/*************** 1.6.0 kael添加 ********************************/
	/** 用户合同代购协议 */
	private LinearLayout btnUserAgreement;
	/** 设置倍投追号 */
	private LinearLayout llSetBeitouZhuihao;
	/** 注数显示 */
	private TextView tvVoteLine;
	/** 金额显示 */
	private TextView tvMoney;
	/** 存放倍投倍数的ArrayList 1~50 */
	private ArrayList<String> beishuNum;
	/** 存放追号期数的ArrayList 1~30 */
	private ArrayList<String> zhuihaoNum;
	/** 选号列表显示倍数的TextView */
	private TextView tvListBeiShu;
	/** 选号列表显示追号期数的TextView */
	private TextView tvListZhuiHao;
	/** 显示倍投追号的Dialog */
	private Dialog beiTouZhuihaoDialog;
	/** 倍投滚轮 */
	private WheelView beishuWheel;
	/** 追号滚轮 */
	private WheelView zhuihaoWheel;
	/** 判断滚轮是否在滚动 */
	private boolean wheelScrolled = false;
	/** 滚轮当前位置的倍投 */
	private String beishuCurrent = Config.NUM1;
	/** 滚轮当前位置的追号 */
	private String zhuihaoCurrent = Config.NUM1;
	/** 点击确定按钮后的倍投 */
	private String beishuEnd = Config.NUM1;
	/** 点击确定按钮后的追号 */
	private String zhuihaoEnd = Config.NUM1;
	/** 设置倍投追号Dialog上完成按钮 */
	private Button btnDialogFinish;
	/** 设置倍投追号Dialog上取消按钮 */
	private Button btnDialogCancel;
	/** 中奖后停止追号的CheckBox */
	private CheckBox cbDialogStop;
	/** 判断是否中奖后停止追号 */
	private boolean isStopZhuihao = false;
	/** 确认提交订单的Dialog */
	private Dialog submitOrderDialog;
	/** 确认提交订单按钮 */
	private Button btnSubmitOrder;
	/** 取消提交订单按钮 */
	private Button btnCancelOrder;
	// 登录作用时间
	private LoginTimeControl loginTimeControl;
	private final static int GETBALANCE_SUCCEED = 1003; // 标识位,获取余额成功
	private final static int GETBALANCE_FAIL = 1004; // 标识位,获取余额失败
	private boolean isGetBalance;
	UserCommunicater userCommunicater;
	/** 复式代购购买进度 */
	private ProgressDialog progressdialogNormalbuy;
	private BuyingCommunicater communicater;
	private static Handler handler;
	// 购买成功后弹出的对话框
	private Dialog successDialog;
	private View.OnClickListener successDialogListener;
	private boolean isTipOnShow = false;
	private Dialog dialogBalanceNotEnough;
	private View.OnClickListener moneyNotEnoughListener;
	private Dialog dialogTermExpired; // 期号变更提示
	public static String currentTerm;
	private ArrayList<String> alVoteData;
	private ArrayList<Hashtable<String, Object>> alBuyingLines;

	/************************************************************/

	public ShiyixuanwuChooseOkPage(Context context, View view) {
		this.view = view;
		this.context = context;
		inflater = ((Activity) context).getLayoutInflater();
		initHandler();
		init();
		refresh();
		updateLotInfo();
	}

	private void init() {

		btnGoBackChoose = view.findViewById(R.id.shiyixuanwu_choose_pre_submit_btn_goBackChoose);
		btnGoBackChoose.setOnClickListener(this);

		btnAddRandom = view.findViewById(R.id.shiyixuanwu_choose_pre_submit_btn_addRandom);
		btnAddRandom.setOnClickListener(this);

		btnClear = view.findViewById(R.id.shiyixuanwu_choose_pre_submit_btn_clearList);
		btnClear.setOnClickListener(this);

		btnBuy = (Button) view.findViewById(R.id.shiyixuanwu_choose_pre_submit_btn_buy);
		btnBuy.setOnClickListener(this);

		tvVoteLine = (TextView) view.findViewById(R.id.shiyixuanwu_choose_pre_submit_tv_voteLine);
		tvMoney = (TextView) view.findViewById(R.id.shiyixuanwu_choose_pre_submit_tv_money);
		btnUserAgreement = (LinearLayout) view.findViewById(R.id.shiyixuanwuchooselistact_btn_xieyi);
		btnUserAgreement.setOnClickListener(this);

		lineNumList = (LinearLayout) view.findViewById(R.id.shiyixuanwu_choose_pri_submit_numList);

		llSetBeitouZhuihao = (LinearLayout) view.findViewById(R.id.shiyixuanwuchooselistact_btn_setbeitou);
		llSetBeitouZhuihao.setOnClickListener(this);

		tvListBeiShu = (TextView) view.findViewById(R.id.shiyixuanwuchooselistact_tv_beishu);
		tvListZhuiHao = (TextView) view.findViewById(R.id.shiyixuanwuchooselistact_tv_qishu);

		itemListener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				int tag = Integer.parseInt(String.valueOf(v.getTag()));

				Hashtable<String, Object> htAboutTheView = ShiyixuanwuChooseOkList.getChooseList().get(tag);
				int style = Integer.parseInt(String.valueOf(htAboutTheView.get(TempData.STYLE)));
				int detail = Integer.parseInt(String.valueOf(htAboutTheView.get(TempData.DETAIL)));

				EDebug.o(this, String.valueOf(htAboutTheView.get(TempData.CODE)));
				container.setPlayType(style, detail, String.valueOf(htAboutTheView.get(TempData.CODE)));

				((Activity) context).setContentView(container.getView());

				/** 2011-8-1 city add for agp title change */
				Message msg = ShiyixuanwuActGroup.handlerShiyixuanwuActGroup.obtainMessage(ShiyixuanwuActGroup.IN_CHOOSE_VIEW, null);
				ShiyixuanwuActGroup.handlerShiyixuanwuActGroup.sendMessage(msg);

				String strDelPlayStyle = ((TextView) v.findViewById(R.id.shiyixuanwu_num_list_tv_playStyle)).getText().toString();
				String strDelNum = ((TextView) v.findViewById(R.id.shiyixuanwu_num_list_tv_number)).getText().toString();
				String strDelVoteInfo = ((TextView) v.findViewById(R.id.shiyixuanwu_num_list_tv_voteInfo)).getText().toString();
				ShiyixuanwuChooseOkList.getChooseList().tempDelete(strDelPlayStyle, strDelNum, strDelVoteInfo);

				deleteLine(v, tag);
			}
		};
		beishuNum = new ArrayList<String>();
		zhuihaoNum = new ArrayList<String>();
		beishuNum = setWheelContent(50);
		zhuihaoNum = setWheelContent(30);
		loginTimeControl = new LoginTimeControl();
		isGetBalance = false;
		progressdialogNormalbuy = ViewerUtil.showProgressDialog(context, Language.POPLOTTERYTIP_BUYING);
		communicater = new BuyingCommunicater();
		userCommunicater = new UserCommunicater();
		alVoteData = new ArrayList<String>();
		alBuyingLines = new ArrayList<Hashtable<String, Object>>();
	}

	private void updateLotInfo() {
		tvVoteLine.setText(String.valueOf(ShiyixuanwuChooseOkList.getChooseList().getVoteLine()));
		int MoneyAll = (ShiyixuanwuChooseOkList.getChooseList().getMoney()) * Integer.parseInt(beishuEnd);
		tvMoney.setText(String.valueOf(MoneyAll));
	}

	/**
	 * @Title: deleteLine
	 * @Description: 删除一行号码
	 * @param line
	 *            要删除的view
	 * @param tag
	 *            view的tag 对应 ShiyixuanwuChooseOkList 里面的相应位置
	 * @return void
	 */
	private void deleteLine(View line, int tag) {
		lineNumList.removeView(line);
		ShiyixuanwuChooseOkList.getChooseList().remove(tag);
		refresh();
	}

	/**
	 * @Title: clearAll
	 * @Description: 清除列表
	 * @return void
	 */
	private void clearAll() {
		lineNumList.removeAllViews();
		ShiyixuanwuChooseOkList.getChooseList().reset();
	}

	/**
	 * @Title: refresh
	 * @Description: 获取最新选好了数据
	 * @return void
	 */
	public void refresh() {

		LayoutParams param = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		param.leftMargin = 10;
		param.rightMargin = 10;

		lineNumList.removeAllViews();
		for (int i = ShiyixuanwuChooseOkList.getChooseList().getSize() - 1; i > 0 - 1; i--) {
			Hashtable<String, Object> htEachLine = ShiyixuanwuChooseOkList.getChooseList().get(i);
			View viewEach = inflater.inflate(R.layout.shiyixuanwu_num_list_each, null);
			viewEach.setTag(i);
			Button btnDelete = (Button) viewEach.findViewById(R.id.shiyixuanwu_num_list_btn_delete);

			TextView tvPlayStyle = (TextView) viewEach.findViewById(R.id.shiyixuanwu_num_list_tv_playStyle);
			TextView tvNum = (TextView) viewEach.findViewById(R.id.shiyixuanwu_num_list_tv_number);
			TextView tvVoteInfo = (TextView) viewEach.findViewById(R.id.shiyixuanwu_num_list_tv_voteInfo);
			TextView tvTouzhuStyle = (TextView) viewEach.findViewById(R.id.shiyixuanwu_num_list_tv_touzhustyle);
			btnDelete.setOnClickListener(this);
			if (String.valueOf(htEachLine.get(TempData.CODE)).length() <= 23) {
				tvTouzhuStyle.setText(Language.MSG_DANSHITOUZHU);
			} else {
				tvTouzhuStyle.setText(Language.MSG_FUSHITOUZHU);
			}
			int style = Integer.parseInt(String.valueOf(htEachLine.get(TempData.STYLE)));
			int detail = Integer.parseInt(String.valueOf(htEachLine.get(TempData.DETAIL)));
			String playStyleWord = ShiyixuanwuPlayStyle.getPlayStyle().getButtonTxt(style, detail);
			tvPlayStyle.setText(LEFT_TAG + playStyleWord + RIGHT_TAG);

			tvNum.setText(String.valueOf(htEachLine.get(TempData.CODE)));
			tvVoteInfo.setText(htEachLine.get(TempData.VOTE_LINE) + ZHU + htEachLine.get(TempData.MONEY) + YUAN);

			viewEach.setOnClickListener(itemListener);
			lineNumList.addView(viewEach, param);
		}
	}

	/**
	 * @Title: addOneRandom
	 * @Description: 添加一行机选号码
	 * @return void
	 */
	public void addOneRandom() {

		container.doRandom();

		View viewEach = inflater.inflate(R.layout.shiyixuanwu_num_list_each, null);
		viewEach.setTag(ShiyixuanwuChooseOkList.getChooseList().getSize());

		LayoutParams param = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		param.leftMargin = 10;
		param.rightMargin = 10;

		Button btnDelete = (Button) viewEach.findViewById(R.id.shiyixuanwu_num_list_btn_delete);

		TextView tvPlayStyle = (TextView) viewEach.findViewById(R.id.shiyixuanwu_num_list_tv_playStyle);
		TextView tvNum = (TextView) viewEach.findViewById(R.id.shiyixuanwu_num_list_tv_number);
		TextView tvVoteInfo = (TextView) viewEach.findViewById(R.id.shiyixuanwu_num_list_tv_voteInfo);
		TextView tvTouzhuStyle = (TextView) viewEach.findViewById(R.id.shiyixuanwu_num_list_tv_touzhustyle);
		btnDelete.setOnClickListener(this);

		String strBuyOK = ShiyixuanwuBuyingInfo.getBuyingInfo().getBuyNum();
		int voteLine = ShiyixuanwuBuyingInfo.getBuyingInfo().getVoteLine();
		String playID = ShiyixuanwuBuyingInfo.getBuyingInfo().getPlayingID();

		int style = ShiyixuanwuPlayStyle.getPlayStyle().getStyle();
		int detail = ShiyixuanwuPlayStyle.getPlayStyle().getDetail();
		String playStyleWord = ShiyixuanwuPlayStyle.getPlayStyle().getButtonTxt(style, detail);
		tvPlayStyle.setText(LEFT_TAG + playStyleWord + RIGHT_TAG);

		tvNum.setText(ShiyixuanwuBuyingInfo.getBuyingInfo().getBuyNum());
		if (ShiyixuanwuBuyingInfo.getBuyingInfo().getBuyNum().length() <= 23) {
			tvTouzhuStyle.setText(Language.MSG_DANSHITOUZHU);
		} else {
			tvTouzhuStyle.setText(Language.MSG_FUSHITOUZHU);
		}
		tvVoteInfo.setText(voteLine + ZHU + voteLine * 2 + YUAN);

		ShiyixuanwuChooseOkList.getChooseList().add(playID, strBuyOK, voteLine, voteLine * 2, String.valueOf(ShiyixuanwuPlayStyle.getPlayStyle().getStyle()),
				String.valueOf(ShiyixuanwuPlayStyle.getPlayStyle().getDetail()));

		// 设置动画效果（右侧飞入）
		viewEach.setAnimation(AnimationUtils.loadAnimation(context, R.anim.push_left_in));

		viewEach.setOnClickListener(itemListener);
		lineNumList.addView(viewEach, 0, param);
	}

	public View getView() {

		ShiyixuanwuChoosePageAct.pageFlag = 1;

		updateLotInfo();
		return view;
	}

	public void setContainer(ShiyixuanwuContainer container) {
		this.container = container;
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.shiyixuanwu_choose_pre_submit_btn_goBackChoose:
			/** 2011-8-1 city add for agp title change */
			Message msg = ShiyixuanwuActGroup.handlerShiyixuanwuActGroup.obtainMessage(ShiyixuanwuActGroup.IN_CHOOSE_VIEW, null);
			ShiyixuanwuActGroup.handlerShiyixuanwuActGroup.sendMessage(msg);

			ShiyixuanwuBuyingInfo.getBuyingInfo().replaceAllData();
			ShiyixuanwuContainer.shiyixuanwuChooseBallSpace.reLoad(context, container.getView(), null);
			((Activity) context).setContentView(container.getView());

			break;

		case R.id.shiyixuanwu_choose_pre_submit_btn_addRandom:

			addOneRandom();

			break;

		case R.id.shiyixuanwu_choose_pre_submit_btn_clearList:

			clearAll();
			beishuEnd = Config.NUM1;
			zhuihaoEnd = Config.NUM1;
			tvListBeiShu.setText(beishuEnd);
			tvListZhuiHao.setText(zhuihaoEnd);

			break;

		case R.id.shiyixuanwu_choose_pre_submit_btn_buy:

			if (ShiyixuanwuChooseOkList.getChooseList().getSize() > 0) {
				if (UserInfo.getUserInfo().getUserSession().length() < 3) {
					context.startActivity(new Intent().setClass(context, LoginAct.class));
					return;
				}
				threadGetUserBalance();
				if (!isGetBalance) {
					ViewerUtil.showTipDialog(context, "余额获取中,请稍候", false);
				} else if (loginTimeControl.isNeedInputPwd()) {
					loginTimeControl.showInputPasswordDialog(context);
				} else if (ShiyixuanwuChoosePageAct.isCanBuy) {
					if (submitOrderDialog == null) {
						showSubmitOrderDialog(Language.MSG_ASK_SUBMIT_ORDER, Language.MSG_SUBMIT);
					}
					submitOrderDialog.show();

				}
				// else {
				//
				// context.startActivity(new Intent().setClass(context, ShiyixuanwuBuyAct.class));
				// }
			} else {
				ViewerUtil.showTipDialog(context, "购买列表不可为空", false);
			}

			break;

		case R.id.shiyixuanwu_num_list_btn_delete:
			View viewLine = (View) v.getParent().getParent().getParent();
			deleteLine(viewLine, Integer.parseInt(String.valueOf(viewLine.getTag())));
			break;
		case R.id.shiyixuanwuchooselistact_btn_xieyi:
			Intent intent = new Intent();
			intent.putExtra(Key.KEY_URL, Config.USER_DAIGOUXIEYI_WEBVIEW_URL);
			intent.putExtra(Key.KEY_TITLE, "用户合同代购协议");
			intent.setClass(context, WebViewActivity.class);
			context.startActivity(intent);
			break;

		case R.id.shiyixuanwuchooselistact_btn_setbeitou:
			if (beiTouZhuihaoDialog == null) {
				showBeitouZhuihaoDialog();
			}
			beiTouZhuihaoDialog.show();
			break;
		// 提交倍投追号
		case R.id.dialog_beitou_zhuihao_btn_submit:
			beishuEnd = beishuCurrent;
			zhuihaoEnd = zhuihaoCurrent;
			beiTouZhuihaoDialog.dismiss();
			tvListBeiShu.setText(beishuEnd);
			tvListZhuiHao.setText(zhuihaoEnd);
			updateLotInfo();
			break;
		// 取消倍投追号
		case R.id.dialog_beitou_zhuihao_btn_cancle:
			beiTouZhuihaoDialog.dismiss();
			break;
		// 购买提交
		case R.id.dialogquit_btn_submit:
			submitOrderDialog.dismiss();
			progressdialogNormalbuy.show();
			setLotteryData();
			threadBuy();
			break;
		// 取消
		case R.id.dialogquit_btn_cancel:
			submitOrderDialog.dismiss();
			break;

		}

		updateLotInfo();
	}

	/**
	 * @Title: showBeitouZhuihaoDialog
	 * @Description: 显示设置倍投 追号的Dialog
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void showBeitouZhuihaoDialog() {
		beiTouZhuihaoDialog = new Dialog(context, R.style.dialog);
		beiTouZhuihaoDialog.getWindow().setContentView(R.layout.dialog_beitou_zhuihao_setting);

		btnDialogFinish = (Button) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_zhuihao_btn_submit);
		btnDialogFinish.setOnClickListener(this);

		btnDialogCancel = (Button) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_zhuihao_btn_cancle);
		btnDialogCancel.setOnClickListener(this);

		cbDialogStop = (CheckBox) beiTouZhuihaoDialog.findViewById(R.id.dialog_cb_stop);
		cbDialogStop.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					isStopZhuihao = true;
				} else {
					isStopZhuihao = false;
				}

			}
		});

		beishuWheel = (WheelView) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_choose_wheel);
		beishuWheel.setAdapter(new NumericWheelAdapter(beishuNum));
		beishuWheel.setCurrentItem(Integer.parseInt(beishuEnd) - 1);
		beishuWheel.addChangingListener(changedListener);
		beishuWheel.addScrollingListener(scrolledListener);
		beishuWheel.setCyclic(true);
		beishuWheel.setVisibleItems(5);
		beishuWheel.setInterpolator(new AnticipateOvershootInterpolator());

		zhuihaoWheel = (WheelView) beiTouZhuihaoDialog.findViewById(R.id.dialog_zhuihao_choose_wheel);
		zhuihaoWheel.setAdapter(new NumericWheelAdapter(zhuihaoNum));
		zhuihaoWheel.setCurrentItem(Integer.parseInt(zhuihaoEnd) - 1);
		zhuihaoWheel.addChangingListener(changedListener);
		zhuihaoWheel.addScrollingListener(scrolledListener);
		zhuihaoWheel.setCyclic(true);
		zhuihaoWheel.setVisibleItems(5);
		zhuihaoWheel.setInterpolator(new AnticipateOvershootInterpolator());
	}

	private OnWheelChangedListener changedListener = new OnWheelChangedListener() {

		@Override
		public void onChanged(WheelView wheel, int oldValue, int newValue) {
			if (!wheelScrolled) {
				updateStatus();
			}
		}
	};

	private OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {

		@Override
		public void onScrollingStarted(WheelView wheel) {
			wheelScrolled = true;
		}

		@Override
		public void onScrollingFinished(WheelView wheel) {
			wheelScrolled = false;
			updateStatus();
		}

	};

	/**
	 * @Title: updateStatus
	 * @Description: 获取滚轮滑动到位置的数值
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void updateStatus() {
		beishuCurrent = beishuNum.get(beishuWheel.getCurrentItem() + 1);
		zhuihaoCurrent = zhuihaoNum.get(zhuihaoWheel.getCurrentItem() + 1);
		EDebug.o(context, "倍数" + beishuCurrent);
		EDebug.o(context, "追号" + zhuihaoCurrent);
	}

	/**
	 * @Title: setWheelContent
	 * @Description: 设置存放追号期数 倍数的ArrayList
	 * @param: @param num
	 * @param: @return 设定文件
	 * @return: ArrayList<String> 返回类型
	 * 
	 */
	private ArrayList<String> setWheelContent(int num) {
		ArrayList<String> array = new ArrayList<String>();
		array.add(Config.NUM0);
		for (int i = 1; i < num + 1; i++) {
			String s = Integer.toString(i);
			array.add(s);
		}
		return array;
	}

	/**
	 * @Title: showSubmitOrderDialog
	 * @Description: 显示提交订单的Dialog
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void showSubmitOrderDialog(String msg, String submit) {
		submitOrderDialog = new Dialog(context, R.style.dialog);
		submitOrderDialog.getWindow().setContentView(R.layout.dialog_quit);
		TextView tvDialogMsg = (TextView) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_tv_msg);
		tvDialogMsg.setText(msg);
		btnSubmitOrder = (Button) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_btn_submit);
		btnSubmitOrder.setText(submit);
		btnSubmitOrder.setOnClickListener(this);
		btnCancelOrder = (Button) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_btn_cancel);
		btnCancelOrder.setOnClickListener(this);
	}

	private void initHandler() {
		handler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				switch (msg.what) {

				case TempData.POP_TERM_EXPIRED_ALERT:

					if (ShiyixuanwuChoosePageAct.isBuyPageShowing && (!isTipOnShow)) {
						String[] str = (String[]) msg.obj;
						showTermExpiredAlert(str[0], str[1]);
					}

					break;

				case TempData.SHIYIXUANWU_BUY_SUCCESS:

					progressdialogNormalbuy.cancel();
					ShiyixuanwuChooseOkList.getChooseList().reset();
					showSuccessTip();

					break;

				case TempData.SHIYIXUANWU_BUY_FAILED:
					progressdialogNormalbuy.cancel();

					if (communicater.getState() == 105) {
						popBalanceNotEnoughAlert();
					} else if (communicater.getState() == 109) {
						ViewerUtil.showTipDialog(context, communicater.getErrorMSG(), false);
					} else {
						ViewerUtil.showTipDialog(context, "通信异常,请查看购彩记录确认是否成功", false);
					}

					break;

				case GETBALANCE_SUCCEED:
					userCommunicater.updataUserInfo();
					isGetBalance = true;

					break;

				case GETBALANCE_FAIL:
					isGetBalance = true;

					break;

				default:
					break;
				}
			}

		};

	}

	private boolean doBuy() {
		int MoneyAll = (ShiyixuanwuChooseOkList.getChooseList().getMoney()) * Integer.parseInt(beishuEnd);
		return communicater.buy(alVoteData, isStopZhuihao, Integer.toString(MoneyAll), currentTerm, Integer.parseInt(beishuEnd), Integer.parseInt(zhuihaoEnd));
	}

	private void threadBuy() {
		new Thread() {

			@Override
			public void run() {
				super.run();
				if (doBuy()) {
					Message msg = handler.obtainMessage(TempData.SHIYIXUANWU_BUY_SUCCESS);
					handler.sendMessage(msg);
				} else {
					Message msg = handler.obtainMessage(TempData.SHIYIXUANWU_BUY_FAILED);
					handler.sendMessage(msg);
				}
			}
		}.start();
	}

	public static void popTermExpiredAlert(String before, String after) {

		String[] str = new String[2];

		str[0] = before;
		str[1] = after;

		Message msg = handler.obtainMessage(TempData.POP_TERM_EXPIRED_ALERT, str);
		handler.sendMessage(msg);
	}

	private void popBalanceNotEnoughAlert() {
		if (dialogBalanceNotEnough == null) {
			dialogBalanceNotEnough = new Dialog(context, R.style.dialog);
		}
		dialogBalanceNotEnough.setContentView(R.layout.shiyixuanwu_alert_money_not_enough);

		if (moneyNotEnoughListener == null) {
			moneyNotEnoughListener = new OnClickListener() {

				@Override
				public void onClick(View v) {
					switch (v.getId()) {
					case R.id.shiyixuanwu_alert_money_not_enough_btn_cancel:
						break;

					case R.id.shiyixuanwu_alert_money_not_enough_btn_recharge:

						context.startActivity(new Intent().setClass(context, RechargeMenuPage.class));

						break;
					}

					dialogBalanceNotEnough.dismiss();
				}
			};
		}

		((Button) dialogBalanceNotEnough.findViewById(R.id.shiyixuanwu_alert_money_not_enough_btn_cancel)).setOnClickListener(moneyNotEnoughListener);
		((Button) dialogBalanceNotEnough.findViewById(R.id.shiyixuanwu_alert_money_not_enough_btn_recharge)).setOnClickListener(moneyNotEnoughListener);

		dialogBalanceNotEnough.show();
	}

	private void showSuccessTip() {

		if (successDialog == null) {
			successDialog = new Dialog(context, R.style.dialog);
			successDialog.setContentView(R.layout.shiyixuanwu_alert_buy_success);
			successDialogListener = new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					switch (v.getId()) {

					case R.id.shiyixuanwu_alert_buy_success_btn_goBackHall:

						successDialog.dismiss();
						ShiyixuanwuChoosePageAct.pageFlag = -1;

						break;

					case R.id.shiyixuanwu_alert_buy_success_btn_goOnChoose:

						successDialog.dismiss();

						if(UserInfo.getUserInfo().isRebuy()){
							if(((Activity)context).getParent() != null){
								((Activity)context).getParent().finish();
								UserInfo.getUserInfo().setRebuy(false);
								return;
							}
						}
						
						ShiyixuanwuChoosePageAct.pageFlag = 0;
						lineNumList.removeAllViews();
						ShiyixuanwuChooseOkList.getChooseList().reset();
						Message msg = ShiyixuanwuActGroup.handlerShiyixuanwuActGroup.obtainMessage(ShiyixuanwuActGroup.IN_CHOOSE_VIEW, null);
						ShiyixuanwuActGroup.handlerShiyixuanwuActGroup.sendMessage(msg);
						ShiyixuanwuBuyingInfo.getBuyingInfo().replaceAllData();
						ShiyixuanwuContainer.shiyixuanwuChooseBallSpace.reLoad(context, container.getView(), null);
						((Activity) context).setContentView(container.getView());
						break;

					default:
						break;
					}
				}
			};
		}

		int MoneyAll = (ShiyixuanwuChooseOkList.getChooseList().getMoney()) * Integer.parseInt(beishuEnd);
		int intBuyMoney = ShiyixuanwuChooseOkList.getChooseList().getMoney();
		((TextView) (successDialog.findViewById(R.id.shiyixuanwu_alert_buy_success_tv_term))).setText(String.valueOf(currentTerm));
		((TextView) (successDialog.findViewById(R.id.shiyixuanwu_alert_buy_success_tv_money))).setText(Integer.toString(MoneyAll));
		((TextView) (successDialog.findViewById(R.id.shiyixuanwu_alert_buy_success_tv_follow))).setText(zhuihaoEnd);
		((TextView) (successDialog.findViewById(R.id.shiyixuanwu_alert_buy_success_tv_voteLine))).setText(String.valueOf(intBuyMoney / 2));
		((TextView) (successDialog.findViewById(R.id.shiyixuanwu_alert_buy_success_tv_balance))).setText(communicater.getBalance());
		((Button) (successDialog.findViewById(R.id.shiyixuanwu_alert_buy_success_btn_goBackHall))).setOnClickListener(successDialogListener);
		Button btnBc = (Button) successDialog.findViewById(R.id.shiyixuanwu_alert_buy_success_btn_goOnChoose);
		btnBc.setOnClickListener(successDialogListener);
		if (UserInfo.getUserInfo().isRebuy()) {
			btnBc.setText("返回详情");
		}
		successDialog.setOnDismissListener(new OnDismissListener() {

			@Override
			public void onDismiss(DialogInterface dialog) {

				isTipOnShow = false;
			}
		});
		isTipOnShow = true;
		successDialog.show();

	}

	private void showTermExpiredAlert(String before, String after) {

		currentTerm = after;

		if (dialogTermExpired == null) {
			dialogTermExpired = new Dialog(context, R.style.dialog);
			dialogTermExpired.setContentView(R.layout.shiyixuanwu_alert_term_expired);

			Button btnClear = (Button) dialogTermExpired.findViewById(R.id.shiyixuanwu_alert_term_expired_btn_clear);
			Button btnCancel = (Button) dialogTermExpired.findViewById(R.id.shiyixuanwu_alert_term_expired_btn_cancel);

			TextView tvMSG = (TextView) dialogTermExpired.findViewById(R.id.shiyixuanwu_alert_term_expired_content);
			tvMSG.setText("第" + before + "期已结束，现在购买为第" + after + "期，确定继续购买吗？");

			View.OnClickListener listener = new OnClickListener() {

				@Override
				public void onClick(View v) {

					dialogTermExpired.dismiss();

					switch (v.getId()) {

					case R.id.shiyixuanwu_alert_term_expired_btn_clear:
						ShiyixuanwuChooseOkList.getChooseList().reset();
						// ShiyixuanwuBuyAct.this.finish();
						break;

					case R.id.shiyixuanwu_alert_term_expired_btn_cancel:
						break;

					default:
						break;
					}
				}
			};

			btnClear.setOnClickListener(listener);
			btnCancel.setOnClickListener(listener);
			dialogTermExpired.show();
		} else {
			dialogTermExpired.show();
		}

	}

	private void threadGetUserBalance() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					Boolean b = userCommunicater.isLoginSucceed(UserInfo.getUserInfo().getUserName(), UserInfo.getUserInfo().getUserPwd());
					if (b) {
						Message msg = handler.obtainMessage(GETBALANCE_SUCCEED, null);
						handler.sendMessage(msg);
					} else {
						Message msg = handler.obtainMessage(GETBALANCE_FAIL, null);
						handler.sendMessage(msg);
					}
				} catch (Exception e) {
					Message msg = handler.obtainMessage(GETBALANCE_FAIL, null);
					handler.sendMessage(msg);

				}
			}
		}.start();
	}

	private void setLotteryData() {
		int size = ShiyixuanwuChooseOkList.getChooseList().getSize();

		for (int i = 0; i < size; i++) {
			Hashtable<String, Object> htEachLine = ShiyixuanwuChooseOkList.getChooseList().get(i);
			alBuyingLines.add(htEachLine);
			String playStyle = TempData.LEFT_TAG + htEachLine.get(TempData.PLAY_STYLE) + TempData.RIGHT_TAG;
			String strLine = String.valueOf(htEachLine.get(TempData.CODE));
			alVoteData.add(playStyle + strLine);
		}
	}

}
